package com.shao.im.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shao.im.entity.Comment;
import com.shao.im.entity.vo.CommentVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 评论表(Comment)表数据库访问层
 *
 * @author makejava
 * @since 2023-08-04 22:23:23
 */
public interface CommentDao extends BaseMapper<Comment> {
    /*select distinct t.cid, if(fr.beizhu,fr.beizhu,u.nickname) nickname, u.header, t.pid, t.uid, t.content, t.create_time
         from `user` u
         left join friends_request fr on u.id = fr.uid
         right join (select cid, pid, uid, content, create_time from `comment` where pid = #{pid}) t
         on u.id = t.uid*/
    /*select c.cid, c.pid, c.content,
          	(
          		if(
          			(select beizhu from friends_relations where uid = 1 and fid in
          				(select fid from friends_relations where uid = 8)
          			),
          			(select beizhu from friends_relations where uid = 1 and fid in
          				(select fid from friends_relations where uid = 8)
          			),
          			(select nickname from `user` where id = 1)
          		)
          	) nickname, c.create_time
          	from `comment` c where c.uid in
          	(
          		select fid from friends_relations where uid = 8
          	)
          	 and pid = 16;*/

    @Select("""
            select distinct t.cid, if(fr.beizhu,fr.beizhu,u.nickname) nickname, u.header, t.pid, t.uid, t.content, t.create_time
                from `user` u
                left join friends_request fr on u.id = fr.uid
                right join (select cid, pid, uid, content, create_time from `comment` where pid = #{pid}) t
                on u.id = t.uid
            """)
    List<CommentVo> queryCommentByPid(Integer pid);
}

